#ifndef US_STATUS_H_
#define US_STATUS_H_

 // Default data boundaries
#define US_STATUS_CONSUMPTION_MIN 0
#define US_STATUS_CONSUMPTION_MAX 20000
#define US_STATUS_BATTERYLIFE_MIN 0
#define US_STATUS_BATTERYLIFE_MAX 100
#define US_STATUS_HEALTH_MIN 0
#define US_STATUS_HEALTH_MAX 8191

#include "AbstractData.h"
/*
 * class USStatus
 * 
 * Represents status data for sentence to be sent from USTAV Server to USTAV Router.
 *
 *  Created on: 22.1.2012.
 *      Author: Hetcheem
 *
 * STATUS               min         max  bytes  + comma    unit  data type
 * -----------------------------------------------------------------------
 * Consumption            0       20000      5        6       ?        int
 * Battery life           0         100      3        4       %        int
 * Health                 0        8191      4        5                int
 * -----------------------------------------------------------------------
 * TOTAL                                    12       15
 * BASE + STATUS                                     33
 */
class USStatus : public AbstractData
{
private:
    // Data members
    int m_consumption;
    int m_batteryLife;
    int m_health;

    // Data handling
    int SerializeSentence(std::stringstream& stream, const bool& isSending)
    {
        // Call base class serialization
        AbstractData::SerializeSentence(stream, isSending);

        if (isSending)
        {
            // Send data to stream
            stream << m_consumption << ',';
            stream << m_batteryLife << ',';
            stream << m_health;
        }
        else
        {
            char comma;
            int consumption, batteryLife, health;

            // Recieve data from stream
            stream >> consumption >> comma;
            stream >> batteryLife >> comma;
            stream >> health;

            // Set the values
            SetHealth(consumption);
            SetBatteryLife(batteryLife);
            SetConsumption(health);
        }

        return 0;
    }

public:
    // Constructor
    USStatus() : AbstractData("USSTA"),
        m_consumption(US_STATUS_CONSUMPTION_MIN), 
        m_batteryLife(US_STATUS_BATTERYLIFE_MIN), 
        m_health(US_STATUS_HEALTH_MIN)
    {}

    // Get
    inline const int& GetConsumption() { return m_consumption; }
    inline const int& GetBatteryLife() { return m_batteryLife; }
    inline const int& GetHealth() { return m_health; }

    // Set
    int SetConsumption(const int& value)
    {
        if (value > US_STATUS_CONSUMPTION_MAX)
        {
            m_consumption = US_STATUS_CONSUMPTION_MAX;
            return 666;
        }
        else if (value < US_STATUS_CONSUMPTION_MIN)
        {
            m_consumption = US_STATUS_CONSUMPTION_MIN;
            return -666;
        }

        m_consumption = value;
        return 0;
    }
    int SetBatteryLife(const int& value)
    {
        if (value > US_STATUS_BATTERYLIFE_MAX)
        {
            m_batteryLife = US_STATUS_BATTERYLIFE_MAX;
            return 666;
        }
        else if (value < US_STATUS_BATTERYLIFE_MIN)
        {
            m_batteryLife = US_STATUS_BATTERYLIFE_MIN;
            return -666;
        }

        m_batteryLife = value;
        return 0;
    }
    int SetHealth(const int& value)
    {
        if (value > US_STATUS_HEALTH_MAX)
        {
            m_health = US_STATUS_HEALTH_MAX;
            return 666;
        }
        else if (value < US_STATUS_HEALTH_MIN)
        {
            m_health = US_STATUS_HEALTH_MIN;
            return -666;
        }

        m_health = value;
        return 0;
    }
};

#endif /* US_STATUS_H_ */
